home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / SeqPups / apps / clustalw.src / calcprf2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-17  |  1.8 KB  |  77 lines  |  [TEXT/R*ch]

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "clustalw.h"
  6.  
  7. /*
  8.  *   Prototypes
  9.  */
  10.  
  11. void calc_prf2(int **profile, char **alignment,
  12.   int *seq_weight,int prf_length, int first_seq, int last_seq);
  13. /*
  14.  *   Global variables
  15.  */
  16.  
  17. extern int max_aa,gap_pos1,gap_pos2;
  18.  
  19. void calc_prf2(int **profile, char **alignment,
  20.   int *seq_weight,int prf_length, int first_seq, int last_seq)
  21. {
  22.  
  23.   int sum1, sum2;    
  24.  
  25.   int i, d;
  26.   int   r;
  27.  
  28.  
  29.   for (r=0; r<prf_length; r++)
  30.     {
  31. /*
  32.    calculate sum2 = number of residues found in this column
  33. */
  34.        sum2 = 0;
  35.        for (i=first_seq; i<last_seq; i++)
  36.          {
  37.             sum2 += seq_weight[i];
  38.          }
  39. /*
  40.    only include matrix comparison scores for those residue types found in this
  41.    column
  42. */
  43.        if (sum2 == 0)
  44.          {
  45.            for (d=0; d<=max_aa; d++)
  46.              profile[r+1][d] = 0;
  47.            profile[r+1][gap_pos1] = 0;
  48.            profile[r+1][gap_pos2] = 0;
  49.          }
  50.        else
  51.          {
  52.            for (d=0; d<=max_aa; d++)
  53.              {
  54.                 sum1 = 0;
  55.                 for (i=first_seq; i<last_seq; i++)
  56.                  {
  57.                   if (d == alignment[i][r]) sum1 += seq_weight[i];
  58.                  }
  59.                 profile[r+1][d] = (int)(10 * (float)sum1 / (float)sum2);
  60.              }
  61.            sum1 = 0;
  62.            for (i=first_seq; i<last_seq; i++)
  63.             {
  64.              if (gap_pos1 == alignment[i][r]) sum1 += seq_weight[i];
  65.             }
  66.            profile[r+1][gap_pos1] = (int)(10 * (float)sum1 / (float)sum2);
  67.            sum1 = 0;
  68.            for (i=first_seq; i<last_seq; i++)
  69.             {
  70.              if (gap_pos2 == alignment[i][r]) sum1 += seq_weight[i];
  71.             }
  72.            profile[r+1][gap_pos2] = (int)(10 * (float)sum1 / (float)sum2);
  73.          }
  74.     }
  75. }
  76.  
  77.